/* 
 * File:   XshareMem.h
 * Author: minaev
 *
 * Created on 31 Октябрь 2013 г., 8:56
 */

#ifndef XSHAREMEM_H
#define	XSHAREMEM_H

#include <stdint.h>
#include <pthread.h>

#include "XshareLine.h"


class XshareMem {
public:
    XshareMem();
    virtual ~XshareMem();
    XshareLine* getLine(uint16_t indx);
    uint16_t getLineLength(uint16_t indx);
    uint8_t getLineBlockLength(uint16_t indx);
    uint32_t getLineBytesLength(uint16_t indx);
    int findInLine(void* findBlock,uint16_t numLine);
    void* read(uint16_t numLine,uint16_t numBlock);
    int write(void* writeBuf,uint16_t numLine,uint16_t numBlock,uint16_t countBlocks);
    void write(void* writeBuf,uint16_t numLine, uint16_t numBlock);
    int addLineBlock(const void* block,uint16_t numLine);
    int addLineBlockWithoutRepeate(const void* block,uint16_t numLine);
    int removeLineBlock(uint16_t nblock,uint16_t numLine);
    int removeLineBlock(void* block,uint16_t numLine);
    void addLine(uint8_t lenBlock);
    uint16_t getCountLines();
    void printMem();
private:
    uint16_t countline; //init in constructor
    uint8_t lensBlockLine[]; //init in constructor
    XshareLine** shareLines;
    pthread_mutex_t accssMem;
    
};

#endif	/* XSHAREMEM_H */

